<?php

class UserIdentity extends CUserIdentity
{
    private $_id;
	private $mail;
	public $password;
    /**
     * Authenticates a user.
     * @return boolean whether authentication succeeds.
     */
    public function authenticate()
    {
        $mail = strtolower($this->username);
		$password = strtolower($this->password);
        $user = Usuarios::model()->find('mail=? AND password=?', array($mail,$password));
        if($user===null)
            $this->errorCode=self::ERROR_USERNAME_INVALID;
		/* else if(!$user->validatePassword($this->password))
				$this->errorCode = self::ERROR_PASSWORD_INVALID;*/
        else{
            // successful login
            $this->_id = $user->idusuario;
			Yii::app()->session['idusuario'] = $user->idusuario;
			Yii::app()->session['nombre'] = $user->nombre;
			Yii::app()->session['apellido'] = $user->apellido;
			Yii::app()->session['mail'] = $user->mail;
			Yii::app()->session['sexo'] = $user->sexo;
			Yii::app()->session['fechaNacimiento'] = $user->fechaNacimiento;
			Yii::app()->session['rol'] = $user->rol;
			Yii::app()->session['habilitado'] = $user->habilitado;
			
            
            $this->errorCode = self::ERROR_NONE;
        }
        return $this->errorCode == self::ERROR_NONE;
    }
    public function getId()
    {
        return $this->_id;
    }	
}










